import React from 'react';
import { Modal, Button, Form, Input, InputNumber, Select, DatePicker, Switch } from 'antd';
import moment from 'moment';

const Item = Form.Item;
const Option = Select.Option;

@Form.create()
class Components extends React.Component {
  constructor(props) {
    super(props);
    this.state = {};
  }
  /**
   * 提交表单到父组件
   */
  onOk = () => {
    this.props.form.validateFieldsAndScroll((err, values) => {
      if (!err) {
        values.openState = values.openState ? 1 : 0;
        this.props.submit(values);
      }
    });
  };
  clear = () => {
    this.props.form.resetFields();
  };

  render() {
    const {
      visible,
      formatData,
      close,
      form: { getFieldDecorator },
    } = this.props;

    const formItemLayout = {
      labelCol: {
        xs: { span: 24 },
        sm: { span: 8 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 12 },
      },
    };
    return (
      <Modal
        title="配置域名解析"
        afterClose={this.clear}
        visible={visible}
        onCancel={close}
        okText="确定"
        cancelText="取消"
        destroyOnClose={true}
        onOk={this.onOk}
      >
        <Form>
          <Item {...formItemLayout} label="域名">
            {getFieldDecorator('domain', {
              rules: [{ required: true, message: '不能为空' }],
              initialValue: formatData && formatData.domain,
            })(<Input />)}
          </Item>
          <Item {...formItemLayout} label="记录值">
            {getFieldDecorator('recordValue', {
              rules: [{ required: true, message: '不能为空' }],
              initialValue: formatData && formatData.recordValue,
            })(<Input />)}
          </Item>

          {/* <Item {...formItemLayout} label="类型">
            {getFieldDecorator('type', {
              rules: [{ required: true, message: '不能为空' }],
              initialValue: formatData && formatData.type,
            })(<Input />)}
          </Item>
          <Item {...formItemLayout} label="视图名称">
            {getFieldDecorator('viewName', {
              rules: [{ required: true, message: '不能为空' }],
              initialValue: formatData && formatData.viewName,
            })(<Input />)}
          </Item>
          <Item {...formItemLayout} label="TTL">
            {getFieldDecorator('ttl', {
              rules: [{ required: true, message: '不能为空' }],
              initialValue: formatData && formatData.ttl,
            })(<InputNumber />)}
          </Item> */}
          <Item {...formItemLayout} label="启用状态">
            {getFieldDecorator('openState', {
              valuePropName: 'checked',
              initialValue: formatData && formatData.openState ? true : false,
            })(<Switch checkedChildren="开" unCheckedChildren="关" />)}
          </Item>
        </Form>
      </Modal>
    );
  }
}

export default Components;
